package ch.il07.converter.persistence.entities;

public class Unit {

	private Integer unitId;
	/**
	 * Name of the unit. example. Meter, kilometer, centimeter.
	 */
	private String name;

	/**
	 * How many times does the baseUnit fit in this unit? example. 1 Meter
	 * (baseUnit) fits 1000 times into 1 km, so the baseUnitDivisor is 1000.0
	 * example 1 centimeter fits 100 times into a meter (baseUnit) so the
	 * baseUnitDivisor for cm == 0.01.
	 */
	private Double divisor;

	/**
	 * How far is the zero-point away from the base Unit zero-Point. example
	 * Fahrenheit = 9/5 * Celsius + 32, so Fahrenheit.baseUnitDivisor = 9/5;
	 * Fahrenheit.baseUnitShift = 32;
	 */
	private Double shift;

	/**
	 * @desc short form of name
	 */
	private String symbol;

	private User owner;

	public Unit(String name, Double factor) {
		this(name, factor, 0.0);
	}

	/**
	 * Creates a new unit.
	 * 
	 * @param name
	 *            Name of the unit. Example: "Centimeter"
	 * @param factor
	 *            Transform from one unit to another. Example (for Centimeter,
	 *            when defaultUnit is "Meter"): 0.01
	 * @param shift
	 *            Adds this number to the result. Example Celsius --> Fahrenheit
	 *            : +32
	 * @param description
	 *            wtf
	 */
	public Unit(String name, Double factor, Double shift) {
		this(name, factor, shift, null);
	}

	public Unit(String name, Double factor, Double shift, User owner) {
		this.name = name;
		this.divisor = factor;
		this.shift = shift;
		this.owner = owner;
	}

	@Override
	public String toString() {
		return String
				.format("[UnitID=%d, Name=%s, Divisor=%f, Shift=%f, Symbol=%s, Owner=%s]",
						unitId, name, divisor, shift, symbol, owner);
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name
	 *            the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the divisor
	 */
	public Double getDivisor() {
		return divisor;
	}

	/**
	 * @param divisor
	 *            the divisor to set
	 */
	public void setDivisor(Double divisor) {
		this.divisor = divisor;
	}

	/**
	 * @return the shift
	 */
	public Double getShift() {
		return shift;
	}

	/**
	 * @param shift
	 *            the shift to set
	 */
	public void setShift(Double shift) {
		this.shift = shift;
	}

	/**
	 * @param unitId
	 *            the unitId to set
	 */
	public void setUnitId(Integer unitId) {
		this.unitId = unitId;
	}

	/**
	 * @return the unitId
	 */
	public Integer getUnitId() {
		return unitId;
	}

	public void setSymbol(String symbol) {
		this.symbol = symbol;
	}

	public String getSymbol() {
		return symbol;
	}

	public void setOwner(User owner) {
		this.owner = owner;
	}

	public User getOwner() {
		return owner;
	}
}